package com.ph.shopping.facade.member.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.ph.shopping.common.util.container.ParamVerifyUtil;
import com.ph.shopping.common.util.result.Result;
import com.ph.shopping.facade.duboresult.DubboResult;
import com.ph.shopping.facade.member.dto.CertificatesAuthDto;
import com.ph.shopping.facade.member.service.ICretificateAuthService;
import com.ph.shopping.facade.member.service.dbservice.facade.ICretificateAuthDbService;

/**
 * 
 * @ClassName: CretificateAuthService
 * @Description: 身份证认证 服务
 * @author tony
 * @date 2017年3月25日
 *
 */
@Component
@Service(version = "1.0.0")
public class CretificateAuthService implements ICretificateAuthService {

	private static final Logger loggger = LoggerFactory.getLogger(CretificateAuthService.class);

	@Autowired
	private ICretificateAuthDbService cretificateAuthDbService;

	@Override
	public Result idCretificateAuth(CertificatesAuthDto dto) {
		loggger.info("身份证认证参数：CertificatesAuthDto ={} ", JSON.toJSONString(dto));
		Result result = DubboResult.getDefResult();
		try {
			String[] fields = { "name", "idCode", "userId" };
			if (ParamVerifyUtil.entityIsNotNullByField(dto, fields)) {
				result = cretificateAuthDbService.idCretificateAuth(dto);
			}
		} catch (Exception e) {
			result = DubboResult.getResultByError(result);
			loggger.error("身份证认证错误", e);
		}
		return result;
	}

	@Override
	public Result getCretificateAuthInfo(String idCode) {
		loggger.info("查询身份证信息认证参数：idCode" + idCode);
		Result result = DubboResult.getDefResult();
		try {
			if(StringUtils.isNotBlank(idCode)){
				result = cretificateAuthDbService.queryCretificateAuthInfo(idCode);
			}
		} catch (Exception e) {
			result = DubboResult.getResultByError(result);
			loggger.error("查询身份证信息错误", e);
		}
		return result;
	}

}
